import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2024-05-24
 * Time: 9:02
 */
public class Main3 {
    static long res = 0;
    static long[] MOD = new long[4];
    static String[] stringB = {"GB", "MB", "KB", "B"};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        scanner.nextLine();
        while (T-- > 0) {
            String s = scanner.nextLine();
            if (s.contains("[")) {
                long temp = 0;
                // 数组
                if (s.charAt(0) == 'i') {
                    temp = 4;
                } else if (s.charAt(0) == 'l') {
                    temp = 8;
                }
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == '[' && s.charAt(i + 1) != ']') {
                        int j = i + 1;
                        while (s.charAt(j) != ']') {
                            j++;
                        }
                        long size = Long.parseLong(s.substring(i + 1, j));
                        res += temp * size;
                        i = j + 1;
                    }
                }
            } else {
                // 正常定义
                if (s.charAt(0) == 'i') {
                    res += 4;
                    // 遍历根据逗号数量 + 1
                    for (int i = 0; i < s.length(); i++) {
                        if (s.charAt(i) == ',') {
                            res += 4;
                        }
                    }
                } else if (s.charAt(0) == 'l') {
                    res += 8;
                    // 遍历根据逗号数量 + 1
                    for (int i = 0; i < s.length(); i++) {
                        if (s.charAt(i) == ',') {
                            res += 8;
                        }
                    }
                } else {
                    for (int i = 0; i < s.length(); i++) {
                        if (s.charAt(i) == '"') {
                            int j = i + 1;
                            while (s.charAt(j) != '"') {
                                res++;
                                j++;
                            }
                            i = j + 1;
                        }
                    }
                }
            }
        }
        int flag = 1;
        for (int i = 3; i >= 0; i--) {
            MOD[i] = flag;
            flag *= 1024;
        }
        for (int i = 0; i <= 3; i++) {
            if (res >= MOD[i]) {
                System.out.print(res / MOD[i] + stringB[i]);
            }
            res %= MOD[i];
        }
    }
}
